<?php
namespace app\admin\controller;

use think\Controller;
use think\Request;

class Invoice extends AdminControl
{
    /**
     * 展示供应商入驻发票索取列表【每个供应商入驻只会存在一条，入驻发票索取记录】
     */
    public function index()
    {
        $field = 'store_id,company_tax,company_name,company_addr,bank_type,bank_account,company_phone,check_state';
        $invoiceLists = model('StoreInvoice')->getItemsByCondition($field,[]);

        $this->assign('invoiceLists',$invoiceLists);
        return  $this->fetch('invoice/index');
    }

    /**
     * 处理供应商发票索取
     * @param Request $request  请求对象
     */
    public function storeInvoiceCheck(Request $request)
    {
        if(!$request->isPost()) ds_json_encode(10001,'请求类型不正确！');

        $state = $request->post('check_state',-1);
        $storeId = $request->post('store_id',0);
        if($state < 0 || empty($storeId))   ds_json_encode(10001,'请求参数不正确！');
        //更新当前供应商索取发票的审核状态
        $handleRes = model('StoreInvoice')->updateInvoiceData(['store_id'=>$storeId,'check_state'=>0],['check_state'=>2]);

        if(!$handleRes) ds_json_encode(10001,'数据更新操作失败！');
        ds_json_encode(10000,'操作成功！');
    }
}
